package com.example.wyz.classplus.ui.fragment;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;

import com.example.wyz.classplus.R;
import com.example.wyz.classplus.base.BaseFragment;
import com.example.wyz.classplus.bean.Course;
import com.example.wyz.classplus.contract.fgm.TimeTableContract;
import com.example.wyz.classplus.presenter.TimeTablePresenter;
import com.example.wyz.classplus.ui.activity.ClassDetailActivity;
import com.example.wyz.classplus.ui.custom.CoursesTable;

import java.util.List;

import butterknife.BindView;

/**
 * Created by 10153 on 2017/5/26.
 */

public class TimeTableFragment extends BaseFragment<TimeTableContract.Presenter>
        implements TimeTableContract.View{

    @BindView(R.id.time_table) CoursesTable coursesTable;

    @Override
    protected void initPresenter() {
        mPresenter = new TimeTablePresenter(this.mContext, this);
    }

    @Override
    protected int getLayout() {
        return R.layout.fragment_time_table;
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater,
                             @Nullable ViewGroup container,
                             @Nullable Bundle savedInstanceState) {
        View view = super.onCreateView(inflater, container, savedInstanceState);
        coursesTable.initCourses(Course.getTestData());
        coursesTable.setOnItemListener(new CoursesTable.OnItemClickListener() {

            @Override
            public void OnItemClick(List<Integer> idList) {
                if(idList.size() == 0){
                    Toast.makeText(getContext(), idList.size(), Toast.LENGTH_SHORT).show();
                }else if(idList.size() == 1){
                    mPresenter.startActivity(ClassDetailActivity.class);
                }else {
                    Toast.makeText(getContext(), idList.size(), Toast.LENGTH_SHORT).show();
                }
            }
        });
        return view;
    }

    @Override
    public void setSelectWeek(int week) {
        Log.d("TimeTableFragment", "setSelectWeek: ");
        if(coursesTable != null){
            coursesTable.setSelectWeek(week);
        }else {
            Log.d("TimeTAbleFragment", "setSelectWeek: null!");
        }
    }

    @Override
    public void setCurrentWeek(int week) {

    }
}
